package net.lengwang.iot.middleware.packet.request;

import net.lengwang.iot.middleware.packet.ParsedPacket;

public class CommonPacketParser {

    public static ParsedPacket parsePacket(ParsedPacket parsedPacket) {
        String hexPacket = parsedPacket.getParsedData();
        parsedPacket.setStartFlag(hexPacket.substring(0, 4));
        parsedPacket.setLength(hexPacket.substring(4, 6));
        parsedPacket.setCommand(hexPacket.substring(6, 8));
        parsedPacket.setVersion(hexPacket.substring(8, 10));
        parsedPacket.setSequenceNumber(hexPacket.substring(10, 14));
        parsedPacket.setCrc16(hexPacket.substring(14, 18));
        parsedPacket.setEndFlag(hexPacket.substring(18, 22));

        return parsedPacket;
    }
}
